package com.my.aslife.exception;


import com.my.aslife.module.common.ErrorCode;
import com.my.aslife.module.common.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResponseResult doBusinessException(BusinessException e){
        log.error("捕获异常：{}, [message: {}]", e, e.getMessage());
        return ResponseResult.failed(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult doException(Exception e) {
        log.error("捕获异常：{}, [message: {}]", e, e.getMessage());
        return ResponseResult.failed(ErrorCode.FAIL_SYSTEM.getCode(),
                ErrorCode.FAIL_SYSTEM.getMessage());
    }
}
